//
// Created by PC on 2017/9/24.
//
#include "MyStack.h"
#include <iostream>
using namespace std;
MyStack::MyStack(int size) {
    m_iSize=size;
    m_pBuffer=new char[size];
    m_iTop=0;
}
MyStack::~MyStack(){
    delete []m_pBuffer;
}
bool MyStack::stackEmpty() {
    if(0==m_iTop)
    {
        return true;
    }
    return false;
}
bool MyStack::stackFull() {
    if (m_iTop==m_iSize)
    {
        return true;
    }
    return false;
}
void MyStack::clearStack() {
    m_iTop=0;
}
int MyStack::StackLength() {
    return m_iTop;
}
bool MyStack::push(char elem) {
    if(!stackFull()){
        m_pBuffer[m_iTop]=elem;
        m_iTop++;
        return true;
    }
    return false;

}
bool MyStack::pop() {
    if(!stackEmpty()){
        m_iTop--;
        return m_pBuffer[m_iTop];
    }
    return false;
}
void MyStack::stackTraverse(bool isFromButton) {
    if(isFromButton){
        for (int i = 0; i <m_iTop; ++i) {
            cout<<m_pBuffer[i]<<",";
        }
        cout<<endl;
    }
    else
    {
        for (int i = m_iTop-1; i>=0; i--) {
            cout<<m_pBuffer[i]<<",";
        }
        cout<<endl;
    }
}

